package com.endbd.census.user.control;

import com.endbd.census.user.model.*;
import com.endbd.census.user.service.ICustomInfoService;
import com.endbd.census.user.service.IInStoreService;
import com.endbd.census.user.service.IOutStoreService;
import com.endbd.census.user.service.IProductService;
import com.endbd.census.user.service.impl.ProductService;
import com.endbd.census.util.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("/census")
public class CensusAction {

    @Autowired
    private ICustomInfoService customInfoService;

    @Autowired
    private IProductService productService;

    @Autowired
    private IOutStoreService outStoreService;

    @Autowired
    private IInStoreService inStoreService;

    @Resource
    private RedisTemplate redisTemplate;

    @RequestMapping("/queryCustomBaseInfo")
    @ResponseBody
    public PageModel<CustomInfo> queryBaseInfoListByCondition(CustomCondition conn,String pagenum,String pagesize){
        System.out.println("进了queryCustomInfo");
        System.out.println("Condition:"+conn);
        System.out.println(pagenum);
        System.out.println(pagesize);
        int pageNum = Integer.parseInt(pagenum);
        int pageSize = Integer.parseInt(pagesize);
        return customInfoService.queryCustomInfoListByCondition(conn,pageNum,pageSize);
    }

    @RequestMapping("/queryCustomSalesDetail")
    @ResponseBody
    public PageModel<CustomInfo> queryCustomSalesDetailByCustomId(String id,String pagenum,String pagesize){
        System.out.println("进了querySalesDetailByCustomId");
        System.out.println("id:"+id);
        System.out.println(pagenum);
        System.out.println(pagesize);
        int pageNum = Integer.parseInt(pagenum);
        int pageSize = Integer.parseInt(pagesize);
        return customInfoService.queryCustomSalesDetailById(id,pageNum,pageSize);
    }

    @RequestMapping("/queryProductInfo")
    @ResponseBody
    public PageModel<ProductInfo> queryProductInfoListByCondition(ProductCondition conn,String pagenum,String pagesize){
        int pageNum = Integer.parseInt(pagenum);
        int pageSize = Integer.parseInt(pagesize);
       /* PageModel<ProductInfo> pageModel = productService.queryProductInfoListByCondition(conn, pageNum, pageSize);
        System.out.println(pageModel);*/

        return productService.queryProductInfoListByCondition(conn,pageNum,pageSize);
    }

    @RequestMapping("/queryProductSalesDetail")
    @ResponseBody
    public PageModel<ProductInfo> queryProductSalesDetailByProductId(String id,String pagenum,String pagesize){
        System.out.println("进了queryProductDetailById");
        System.out.println("id:"+id);
        System.out.println(pagenum);
        System.out.println(pagesize);
        int pageNum = Integer.parseInt(pagenum);
        int pageSize = Integer.parseInt(pagesize);
        return productService.queryProductSalesDetailByProductId(id,pageNum,pageSize);
    }

    @RequestMapping("/queryOutStoreInfo")
    @ResponseBody
    public PageModel<OutStoreInfo> queryOutStoreInfoListByCondition(OutStoreCondition conn,String pagenum,String pagesize){
        System.out.println("进了queryOutStoreInfo");
        System.out.println("Condition:"+conn);
        System.out.println(pagenum);
        System.out.println(pagesize);
        int pageNum = Integer.parseInt(pagenum);
        int pageSize = Integer.parseInt(pagesize);
        return outStoreService.queryOutStoreInfoListByCondition(conn,pageNum,pageSize);
    }

    @RequestMapping("/queryOutStoreDetail")
    @ResponseBody
    public PageModel<OutStoreInfo> queryOutStoreDetailByOutStoreId(String id,String pagenum,String pagesize){
        System.out.println("进了queryOutStoreDetailById");
        System.out.println("id:"+id);
        System.out.println(pagenum);
        System.out.println(pagesize);
        int pageNum = Integer.parseInt(pagenum);
        int pageSize = Integer.parseInt(pagesize);
        return outStoreService.queryOutStoreDetailByOutStoreId(id,pageNum,pageSize);
    }

    @RequestMapping("/queryInStoreInfo")
    @ResponseBody
    public PageModel<InStoreInfo> queryInStoreInfoListByCondition(InStoreCondition conn,String pagenum,String pagesize){
        System.out.println("进了queryInStoreInfo");
        System.out.println("Condition:"+conn);
        System.out.println(pagenum);
        System.out.println(pagesize);
        int pageNum = Integer.parseInt(pagenum);
        int pageSize = Integer.parseInt(pagesize);
        PageModel<InStoreInfo> inStoreInfos = inStoreService.queryInStoreInfoListByCondition(conn,pageNum,pageSize);
        System.out.println("inStoreInfos"+inStoreInfos);
        return inStoreInfos;
    }

    @RequestMapping("/queryInStoreDetail")
    @ResponseBody
    public PageModel<InStoreInfo> queryInStoreDetailByInStoreId(String id,String pagenum,String pagesize){
        System.out.println("进了queryInStoreDetailById");
        System.out.println("id:"+id);
        System.out.println(pagenum);
        System.out.println(pagesize);
        int pageNum = Integer.parseInt(pagenum);
        int pageSize = Integer.parseInt(pagesize);
        return inStoreService.queryInStoreDetailByInStoreId(id,pageNum,pageSize);
    }
}
